<template>
  <button class="g-button" :class="{ [`icon-${iconposition}`]: true }">
    <!-- <svg class="icon" v-if="icon">
      <use :xlink:href="`#icon-${icon}`"></use>
    </svg> -->
    <g-icon v-if="icon" :iconname="icon" class="icon"></g-icon>
    <div class="content">
      <slot></slot>
    </div>
  </button>
</template>

<script>
export default {
  props: {
    icon: {},
    iconposition: {
      type: String,
      default: "left",
      validator(val) {
        //属性检查器，val用户传的参数，用来检查用户传参数是否正确
        var q = 123;
        console.log(typeof q);
        typeof q;
        return val !== "left" && val !== "right" ? false : true;
      },
    },
  },
};
</script>
<style lang='scss'>
.g-button {
  font-size: var(--font-size);
  height: var(--button-height);
  padding: 0px 1em;
  border-radius: var(--button-radius);
  background-color: var(--button-bg);
  border: 1px solid var(--button-border-color);
  vertical-align: middle;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  &:hover {
    border-color: var(--border-hover-color);
  }
  &:active {
    border-color: var(--button-border-color);
    background-color: var(--button-active-bg);
  }
  > .icon {
    order: 1;
    margin-right: 0.5em;
  }
  > .content {
    order: 2;
  }
  &.icon-right {
    > .icon {
      order: 2;
    }
    > .content {
      order: 1;
      margin-right: 0.51em;
    }
  }
}
</style>